package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.Recharge;
import cn.wolfcode.crm.query.RechargeQueryObject;
import cn.wolfcode.crm.service.IRechargeService;
import cn.wolfcode.crm.util.JsonResult;
import cn.wolfcode.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


@Controller
@RequestMapping("/recharge")
public class RechargeController {

    @Autowired
    private IRechargeService rechargeService;


    @RequestMapping("")
    public String index(){
        return "recharge";
    }


    @RequestMapping("/list")
    @ResponseBody
    public PageResult list(RechargeQueryObject qo){
        return rechargeService.list(qo);
    }


    //保存充值信息
    @RequestMapping("/rechargeMoney")
    @ResponseBody
    public JsonResult rechargeMoney(Recharge recharge){
        try {
            rechargeService.rechargeMoney(recharge);
            return new JsonResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new JsonResult("充值失败!");
        }
    }
    //扣费
    @RequestMapping("/unrechargeMoney")
    @ResponseBody
    public JsonResult unrechargeMoney(Recharge recharge){
        try {
            rechargeService.unrechargeMoney(recharge);
            return new JsonResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new JsonResult("操作失败!");
        }
    }
    //退还
    @RequestMapping("/returnMoney")
    @ResponseBody
    public JsonResult returnMoney(Recharge recharge){
        try {
            rechargeService.returnMoney(recharge);
            return new JsonResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new JsonResult("操作失败!");
        }
    }


}
